/*
 * Created by IntelliJ IDEA.
 * User: zslajchrt
 * Date: Feb 23, 2011
 * Time: 10:56:32 PM
 */
package chloroform.l10n

import chloroform.ProjectEntry
import scaladuct.l10n.{ResourceBundleCommonMetaData, L10nProperties}
import java.util.{ResourceBundle, Locale}

trait ResourceBundleProjectMetaDataSource extends ProjectMetaDataSource with L10nProperties {
  def projectMetaData(locale: Locale) = {
    bundle(locale) match {
      case None => None
      case Some(bundle) => Some(new ResourceBundleProjectMetaData(bundle))
    }
  }
}

class ResourceBundleProjectMetaData(resourceBundle: ResourceBundle) extends ProjectMetaData {

  def projectEntryMeta(entry: ProjectEntry) = {
    Some(new ResourceBundleCommonMetaData(resourceBundle, entry.name + '.'))
  }

  def projectMeta = {
    Some(new ResourceBundleCommonMetaData(resourceBundle, ""))
  }
}